import axios from 'axios'
// 基准路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1'
// 请求拦截器
axios.interceptors.request.use(function (config) {
  // Do something before request is sent
  // console.log(config)
  // 取出存的token
  let mytoken = localStorage.getItem('mytoken') || ''
  // 判断token是否存在
  if (mytoken) {
    config.headers['Authorization'] = mytoken
  }
  return config
}, function (error) {
  // Do something with request error
  return Promise.reject(error)
})
// 这是登录的接口
export const logiuser = obj => {
  return axios.post('/login', obj).then(res => res.data)
}
// 这是获取用户列表的接口
export const userdata = obj => {
  return axios.get('/users', obj).then(res => res.data)
}
// 这是删除用户的接口
export const delteUser = id => {
  return axios.delete(`/users/${id}`).then(res => res.data)
}
// 这是用户添加的接口
export const AddUserinfo = obj => {
  return axios.post('users', obj).then(res => res.data)
}
// 编辑获取单个用户信息
export const EditInfo = (id, obj) => {
  return axios.put(`/users/${id}`, obj).then(res => res.data)
}
// 切换用户状态
export const Switchover = obj => {
  return axios.put(`/users/${obj.id}/state/${obj.mg_state}`).then(res => res.data)
}
// 获取角色授权
export const Casting = () => axios.get('/roles').then(res => res.data)
// 角色分配在Users.Vue中
export const distribute = obj => axios.put(`users/${obj.id}/role`, {rid: obj.cid}).then(res => res.data)
// 权限列表
export const RightsData = type => axios.get(`rights/${type}`).then(res => res.data)
// 获取左侧菜单列表数据
export const Homemenu = () => axios.get('/menus').then(res => res.data)
